package psi.controllers;

import com.jfinal.aop.Before;
import com.jfinal.ext.interceptor.POST;
import com.jfinal.plugin.activerecord.Record;

import psi.services.PermissionService;

/**
 * 权限 Controller
 * 
 * @author 李静波
 *
 */
public class PermissionController extends PSIBaseController {

	/**
	 * 权限管理 - 主页面
	 */
	public void index() {
		initVarsForView();

		setAttr("title", "权限管理");

		render("index.html");
	}

	@Before(POST.class)
	public void roleList() {
		renderJson(new PermissionService().roleList());
	}

	@Before(POST.class)
	public void permissionList() {
		String roleId = getPara("roleId");
		renderJson(new PermissionService().permissionList(roleId));
	}

	@Before(POST.class)
	public void userList() {
		String roleId = getPara("roleId");
		renderJson(new PermissionService().userList(roleId));
	}

	@Before(POST.class)
	public void selectPermission() {
		String idList = getPara("idList");
		renderJson(new PermissionService().selectPermission(idList));
	}

	@Before(POST.class)
	public void selectUsers() {
		String idList = getPara("idList");
		renderJson(new PermissionService().selectUsers(idList));
	}

	@Before(POST.class)
	public void dataOrgList() {
		String roleId = getPara("roleId");
		String permissionId = getPara("permissionId");
		renderJson(new PermissionService().dataOrgList(roleId, permissionId));
	}

	@Before(POST.class)
	public void editRole() {
		Record params = new Record();
		params.set("id", getPara("id"));
		params.set("name", getPara("name"));
		params.set("userIdList", getPara("userIdList"));
		params.set("permissionIdList", getPara("permissionIdList"));
		
		renderJson(new PermissionService().editRole(params));
	}
}
